import React, { Component } from 'react'

export default class Demo extends Component {

    state = {count: 0}

    add = () =>{
        // 对象式的setState
        // this.setState({
        //     count: this.state.count + 1
        // }, () => {
        //     console.log('!!!!当前求和为：', this.state.count)
        // })
        // console.log('@@@@当前求和为：', this.state.count)

        // 函数式的setState
        this.setState((state, props) => {
           return {count: state.count + 1}
        }, () => {
                console.log('!!!!当前求和为：', this.state.count)
            })
    }

  render() {
    return (
      <div>
        <h1>当前求和为{this.state.count}</h1>
        <button onClick={this.add}>+1</button>
      </div>
    )
  }
}
